8 + 3 - 8 / 2 = 8 + 3 - 4 -----
The single / has higher priority than the + and the -, so it is done first. Now there are two operators of equal priority, so they are done left to right:
8 + 3 - 4 = 11 + 4 = 15 -----
operator |
meaning | priority |
---|---|---|
^ |
power | 1 |
- |
negation | 2 |
* |
multiply | 3 |
/ |
divide | 3 |
+ |
addition | 4 |
- |
subtraction | 4 |
Examine the operator priority chart again. Notice that "-" is in the chart in two places. As you saw in chapter one, this is because "-" is used in two different ways:
Since "negation" has high priority, it will be done first:
10 + -8 / 2 = 10 + (-8)/2 = 10 + -4 = 6
What is the result of the following?
-12 + 2 + 4